{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ee1116ed",
   "metadata": {},
   "source": [
    "# 要求：\n",
    "1.运行程序后，让用户输入支付宝余额input，然后打印info我们的商品列表给用户。\n",
    "\n",
    "2.让用户输入商品编号进行商品的购买。0-value\n",
    "\n",
    "3.用户选择商品后，检查用户的余额是否够，若够则直接扣款，不够则提醒用户。加法计算金额，条件判断if，提醒用户余额不足，余额足够\n",
    "\n",
    "4.用户可以随时退出购买，推出时打印用户已购买的商品和支付宝余额。您的余额还有多少"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a3f6cb80",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入您的余额：10\n",
      "------ goods list ------\n",
      "纯奶茶 5元\n",
      "西米奶茶 6元\n",
      "珍珠奶茶 7元\n",
      "啵啵奶茶 7元\n",
      "请输入正确的商品编号:1\n",
      "【西米奶茶】已经加入您的购物车，您的【余额】还有 4 元\n",
      "------ goods list ------\n",
      "纯奶茶 5元\n",
      "西米奶茶 6元\n",
      "珍珠奶茶 7元\n",
      "啵啵奶茶 7元\n",
      "请输入正确的商品编号:A\n",
      "请输入正确的【商品编码】或按照输入提示输入\n",
      "------ goods list ------\n",
      "纯奶茶 5元\n",
      "西米奶茶 6元\n",
      "珍珠奶茶 7元\n",
      "啵啵奶茶 7元\n"
     ]
    }
   ],
   "source": [
    "goods_list = [[\"纯奶茶\",5],[\"西米奶茶\",6],[\"珍珠奶茶\",7],[\"啵啵奶茶\",7]]\n",
    "\n",
    "user_shopping_list = []\n",
    "\n",
    "# 用户输入：input\n",
    "Alipay = int(input(\"请输入您的余额：\"))\n",
    "\n",
    "while True:\n",
    "    print('------ goods list ------')  \n",
    "    for i in range(len(goods_list)):\n",
    "        print(goods_list[i][0],str(goods_list[i][1])+\"元\")\n",
    "    choice = input(\"请输入正确的商品编号:\")\n",
    "    if choice.isdigit():# 判断字符串是否为数值\n",
    "        choice = int(choice)\n",
    "        if choice >= len(goods_list):\n",
    "            print(\"您输入的商品不存在，请检查后重新输入\")\n",
    "        else:\n",
    "            if Alipay > goods_list[choice][1]:\n",
    "                Alipay = Alipay - goods_list[choice][1]\n",
    "                user_shopping_list.append(goods_list[choice])\n",
    "                print(\"【%s】已经加入您的购物车，您的【余额】还有 %s 元\"% (goods_list[choice][0],Alipay))\n",
    "            else:\n",
    "                print(\"您的余额不足，请更换支付方式\")\n",
    "    elif choice == \"\":\n",
    "        print(\"您的购物车：\",user_shopping_list)\n",
    "        print(\"您的账户余额： %s 元\"%(Alipay))\n",
    "        break\n",
    "    else:\n",
    "        print(\"请输入正确的【商品编码】或按照输入提示输入\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "87bc2348",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
